<template>
	<view class="wrap">
		<view class="content" v-html="content"> </view>
		<view class="input-box" @click="logoutFunOne" v-if="showBtn && type == 2">
			<view class="name">
				<image src="/static/images/my6.png"></image>
				注销账号
			</view>
		</view>
		<!-- <view class="base_box">
			<view class="tips_box">
				<view class="tips_left">
					<view class="tips_left_icon" @click="isPick = !isPick">
						<image v-if="isPick" :src="imgUrl + '5.png'" mode="aspectFill"></image>
						<image v-else :src="imgUrl + '9.png'" mode="aspectFill"></image>
					</view>
					<view class="tips_left_text">
						我已阅读并同意<text @click="$u.route('/pages/login/privacyPact')">《隐私协议》</text>
					</view>
				</view>
			</view>
		</view> -->
	</view>
</template>

<script>
	import {
		getTreaty,
		deletedUser
	} from "@/api/api";

	export default {
		data() {
			return {
				content: "",
				type: 1,
				showBtn: false,
			};
		},
		onLoad(opition) {
			let type = "user";
			if (opition.type == 1) {
				type = "user";
				uni.setNavigationBarTitle({
					title: "用户协议",
				});
			} else {
				this.type = opition.type;
				type = "pri";
				uni.setNavigationBarTitle({
					title: "隐私协议",
				});
			}
			uni.showLoading({
				title: "获取中",
			});
			getTreaty({
					type: type,
				})
				.then((res) => {
					this.content = res.data;
					uni.hideLoading();
				})
				.catch((e) => {
					uni.hideLoading();
					uni.$u.toast(typeof e === "string" ? e : "请检查网络连接");
				});
			this.getUserInfo();
		},

		methods: {
			getUserInfo() {
				let token = uni.getStorageSync("token");
				if (token) {
					this.showBtn = true;
				} else {
					this.showBtn = false;
				}
			},

			logoutFunOne() {
				const that = this;
				uni.showModal({
					title: "警告",
					// 是否注销账号,注销后5天内将无法注册和登录
					content: "是否确认注销账号，请注意该操作不可逆！",
					success(res) {
						if (res.confirm) {
							deletedUser().then((res) => {
								console.log(res, '[]')
								if (res.code == 1) {
									uni.showToast({
										title: "注销成功",
										icon: "none",
										mask: true,
										complete: () => {
											that.$store.commit("LOGOUT");
											uni.setStorageSync("token", "");
											// let loginArr = uni.getStorageSync("loginArr")
											// if (!loginArr) loginArr = []
											// if (loginArr.indexOf(that.userInfo.id) == -1) {
											//   loginArr.push(that.userInfo.id)
											// }
											uni.setStorageSync("isLogOff", true);
											// uni.setStorageSync('loginArr', loginArr);
											uni.reLaunch({
												url: "/pages/login/login",
											});
										},
									});
								} else {
									uni.showToast({
										title: res.info,
										icon: "none",
										mask: true,
									});
								}
							}).catch(err => {
								console.log(err, '[报错信息]')
							});
						}
					},
				});
			},
		},
	};
</script>

<style lang="scss">
	.wrap {
		padding-top: 30rpx;
		width: 750rpx;
		overflow: hidden;

		.content {
			padding: 0 30rpx;
			font-size: 28rpx;
			text-align: left;
			color: #4d4d4d;
			line-height: 40rpx;
		}

		.base_box {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 750rpx;
			height: 120rpx;
			background: #ffffff;
			box-shadow: 0rpx 0rpx 6rpx 0rpx rgba(0, 35, 70, 0.08);
			display: flex;
			align-items: center;
			padding: 0 30rpx;

			.tips_box {
				.tips_left {
					display: flex;
					align-items: center;

					.tips_left_icon {
						width: 24rpx;
						height: 24rpx;
						font-size: 0;

						image {
							width: 100%;
							height: 100%;
						}
					}

					.tips_left_text {
						margin-left: 15rpx;
						font-size: 24rpx;
						color: #737373;

						text {
							margin: 0 6rpx;
							color: #df2433;
						}
					}
				}
			}
		}
	}

	.input-box {
		width: 660rpx;
		line-height: 128rpx;
		border-radius: 20rpx;
		background-color: white;
		padding: 0 30rpx;
		overflow: hidden;
		margin: 30rpx auto;
		color: #434242;
		font-size: 30rpx;
		font-weight: 400;
		position: relative;
		z-index: 1;

		.name {
			width: 60%;
			display: inline-block;
			vertical-align: top;

			image {
				width: 38rpx;
				height: 38rpx;
				display: inline-block;
				vertical-align: top;
				margin: 45rpx 15rpx 0 0;
			}
		}

		.value {
			width: 40%;
			display: inline-block;
			vertical-align: top;
			text-align: right;

			image {
				width: 16rpx;
				height: 30rpx;
				display: inline-block;
				vertical-align: top;
				margin: 50rpx 0 0 0;
			}
		}
	}
</style>